package com.njy.cloudalibaba.consumer.controller;


import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.njy.pojo.Dept;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;


@RestController

public class OrderNacosController {

    private final static Logger LOGGER = LoggerFactory.getLogger(OrderNacosController.class);

    @Value("${service-url.nacos-user-service}")
    private String serviceUrl;

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private AsyncMethod asyncMethod;

    @PostMapping("/consumer/payment/nacos/{id}")
    public String getPayment(@PathVariable("id") Integer id, @RequestBody Dept dept) {
      /*  asyncMethod.testThreadPoolMethod();
        asyncMethod.testThreadPoolTaskMethod2();
        asyncMethod.testThreadPoolTaskMethod3();
        asyncMethod.testAsyncMethod();*/

        //asyncMethod.testThreadPoolTaskMethod2();


        //LOGGER.info("----83----");
        LOGGER.info("dept --->"+dept.toString());
      //  String forObject = restTemplate.getForObject(serviceUrl + "/payment/nacos/" + id, String.class,dept);
        ResponseEntity<Map> responseEntity =
                restTemplate.postForEntity(serviceUrl + "/payment/nacos/" + id, dept, Map.class);
        Map<String ,String> body = responseEntity.getBody();
        JSONObject jsonObject = JSONUtil.parseFromMap(body);
        return jsonObject.toString();
    }
}
